package adminServlet;

import java.io.IOException;
import java.sql.Timestamp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import routeEntity.Route;
import routeImplment.RouteImplment;

/**
 * Servlet implementation class AdminResetRoute
 */
public class AdminResetRoute extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminResetRoute() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int Rid=Integer.parseInt(request.getParameter("Rid"));
		String Rname = request.getParameter("Rname");
		String fromStation = request.getParameter("fromStation");
		String fromTime = request.getParameter("fromTime");
		String toStation = request.getParameter("toStation");
		String toTime = request.getParameter("toTime");
		int seatPrice=Integer.parseInt(request.getParameter("seatPrice"));
		int seatNumber=Integer.parseInt(request.getParameter("seatNumber"));
		HttpSession session =request.getSession();
		RouteImplment routeImplment=new RouteImplment();
		
		String fromTime1=fromTime.substring(0, 10)+' '+fromTime.substring(11, 16)+":00.0";
		Timestamp f=Timestamp.valueOf(fromTime1);		
		String toTime1=toTime.substring(0, 10)+' '+toTime.substring(11, 16)+":00.0";
		Timestamp t=Timestamp.valueOf(toTime1);
		
	//将表单获得的用户信息封装为一个Route对象
		Route route=routeImplment.RouteQuery(Rid);
		route.setRname(Rname);
		route.setFromStation(fromStation);
		route.setFromTime(f);
		route.setToStation(toStation);
		route.setToTime(t);
		route.setSeatNumber(seatNumber);
		route.setSeatPrice(seatPrice);
			if(routeImplment.ResetRoute(Rid, route)) {
				session.setAttribute("routeList",routeImplment.GetAllRoute());
				request.getRequestDispatcher("adminRoute.jsp").forward(request, response);
			}else {
				//插入失败跳转到出错提示页面
				System.out.print("修改路线失败");
			}
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
